<template>
  <h1>员工列表综合练习</h1>
  <el-form style="width: 50%; margin: 0 auto">
    <el-form-item label="姓名">
      <el-input placeholder="请输入姓名" v-model="people.name"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input placeholder="请输入工资" v-model="people.salary"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input placeholder="请输入岗位" v-model="people.job"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="f">点我提交</el-button>
    </el-form-item>

  </el-form>
  <el-table :data="arr"  style="width: 50%;margin: 0 auto">
    <el-table-column type="index" label="编号" width="80" align="center"></el-table-column>
    <el-table-column prop="name" label="姓名" align="center"></el-table-column>
    <el-table-column prop="salary" label="薪水" align="center"></el-table-column>
    <el-table-column prop="job" label="岗位" align="center"></el-table-column>
    <el-table-column label="操作" #default="scope">
      <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
   </el-table-column>
  </el-table>

</template>

<script setup>

import {ref} from "vue";

const people = ref({name: '', salary: '', job: ''})
const arr = ref([]);
const f = () => {
  arr.value.push(people.value);
  people.value = {};
}

const del=(i , emp)=>{
  if(confirm('是否删除'+emp.name+'?')){
    arr.value.splice(i,1);
  }
}
</script>

<style scoped>

</style>